<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>系统设置</title>
    <link rel="stylesheet" href="/static/public/layui/css/layui.css">
    <script type="text/javascript" src="/static/public/layui/layui.js"></script>
</head>
<body style="padding: 15px">
<div class="layui-card">
    <div class="layui-card-header">网站设置</div>
    <div class="layui-card-body">
        <form class="layui-form">
            @csrf
            <div class="layui-form-item">
                <label class="layui-form-label">网站名称</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="title" value="{{$setting['vals']['title']}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">网站LOGO</label>
                <div class="layui-input-inline">
                    <img id="preview_img" src="{{ $logo['vals'] }}" style="height: 30px">

                    <button type="button" class="layui-btn" id="btn_upload">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">关键词</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="keywords" value="{{$setting['vals']['keywords']}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">网站描述</label>
                <div class="layui-input-inline">
                    <textarea class="layui-textarea" name="descs">{{$setting['vals']['descs']}}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备案号</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="icp" value="{{$setting['vals']['icp']}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">公安备</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="rcode" value="{{$setting['vals']['rcode']}}">
                </div>
            </div>

            <div class="layui-input-block">
                <button type="button" class="layui-btn" onclick="save()">保存</button>
            </div>
        </form>
    </div>
</div>


<script type="text/javascript">
    layui.use(['layer','upload','form'],function(){
        $ = layui.jquery;
        layer = layui.layer;
        var _token =  $('input[name="_token"]').val();
        upload = layui.upload;


        //执行实例
        var uploadInst = upload.render({
            elem: '#btn_upload' //绑定元素
            ,url: '/admin/files/upload_img' //上传接口
            ,data:{_token:_token}
            ,done: function(res){
                //上传完毕回调
                console.log(res);
                $('#preview_img').attr('src',res.data.src);
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });

    function save(){
        var data = {};
        data._token   = $('input[name="_token"]').val();
        data.title = $.trim($('input[name="title"]').val());
        data.thumb    = $('#preview_img').attr('src');
        data.keywords    =  $.trim($('input[name="keywords"]').val());
        data.descs    =  $.trim($('input[name="descs"]').val());
        data.icp   =  $.trim($('input[name="icp"]').val());
        data.rcode   =  $.trim($('input[name="rcode"]').val());
        if(data.title==''){
            return layer.alert('网站名称不能为空',{icon:2});
        }
        $.post('/admin/setting/save',data,function(res){
            if(res.code>0){
                return layer.alert(res.msg,{icon:2});
            }
            layer.msg(res.msg);
        },'json');
    }
</script>
</body>
</html>
